package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.TokenUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/ws/")
public class TokenController extends BaseController {

    @GetMapping("/getToken")
    @CrossOrigin
    public AjaxResult getWsToken() {
        LoginUser loginUser = getLoginUser();
        Integer userId = loginUser.getUserId().intValue();
        String token = TokenUtils.genrateToken(userId,"");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        return AjaxResult.success(hashMap);
    }
}
